export function basicsPages(moduleCode, data, useIndex = false) {
  const fields = {}
  data.forEach((element, index) => {
    if (element.isOpen) {
      fields[element.fieldCode] = {
        model: element.fieldCode,
        type: "",
        sort: useIndex ? index + 1 : element.sort,
        wrapper: {
          label: element.fieldName
        },
        customize: {
          disabled: !!(
            moduleCode === "basic" && (element.fieldCode === 'name' || element.fieldCode === 'idCard' || element.fieldCode === 'birthday' || element.fieldCode === 'empAge' || element.fieldCode === 'gender')
            || (moduleCode === "contact" && (element.fieldCode === 'phone'))||(moduleCode === "socAndPf" && (element.fieldCode === "startPaymentDate" || element.fieldCode === "insuredCity"))),
          placeholder: (element.fieldType === 2) || (element.fieldType === 4) || (element.fieldType === '2') || (element.fieldType === '4') ? `请输入${element.fieldName}` : `请选择${element.fieldName}`,
          format: element.fieldType === '3' ? "YYYY-MM-DD" : ""
        },
        decorator: {
          "initialValue": undefined,
          rules: [
            {
              required: (moduleCode === "basic" && (element.fieldCode === 'name' || element.fieldCode === 'idCard' || element.fieldCode === 'birthday' || element.fieldCode === 'empAge' || element.fieldCode === 'gender')) ? false : element.isNecessary,
              message: (element.fieldType === 2) || (element.fieldType === 4) || (element.fieldType === '2') || (element.fieldType === '4') ? `请输入${element.fieldName}` : `请选择${element.fieldName}`
            }
          ]
        }

      }

      if (element.fieldType === 1 || element.fieldType === "1") {
        let options = []
        if (element.dropDownEnumList) {
          element.dropDownEnumList.forEach((item, index) => {
            for (const key in item) {
              if (item[key] === "true") {
                item[key] = true
              }
              if (item[key] === "false") {
                item[key] = false
              }
            }
          });
          options = element.dropDownEnumList
        }
        if (element.dropDownArray) {
          element.dropDownArray.forEach(element => {
            options.push({
              value: element, label: element
            })
          });
        }
        fields[element.fieldCode].customize.options = options
        fields[element.fieldCode].type = "select"
      }

      if (element.fieldType === 2 || element.fieldType === "2") {
        fields[element.fieldCode].type = "input"
      }

      if (element.fieldType === 3 || element.fieldType === "3") {
        fields[element.fieldCode].type = "date"
      }

      if (element.fieldType === 4 || element.fieldType === "4") {
        fields[element.fieldCode].type = "textarea"
      }

      if (element.fieldType === 5 || element.fieldType === "5") {
        fields[element.fieldCode].type = "number"
        fields[element.fieldCode].decorator.rules.push({
          pattern: "^\\d+$",
          message: `${element.fieldName}必须为数字`
        })
      }

      if (element.fieldType === 6 || element.fieldType === "6") {
        fields[element.fieldCode].type = "area"
      }

      if (element.fieldType === 7 || element.fieldType === "7") {
        fields[element.fieldCode].type = "upload"
      }

      if (moduleCode === "basic" && (element.fieldCode === 'name' || element.fieldCode === 'idCard' || element.fieldCode === 'birthday')) {
        fields[element.fieldCode].type = "input"
        fields[element.fieldCode].decorator.rules = {
          required: false,
          message: (element.fieldType === 2) || (element.fieldType === 4) || (element.fieldType === '2') || (element.fieldType === '4') ? `请输入${element.fieldName}` : `请选择${element.fieldName}`
        }
      }
      if (element.fieldCode === 'phone' || element.fieldCode === 'witPhone') {
        fields[element.fieldCode].decorator.rules.push({
          pattern: "^1[3456789]\\d{9}$",
          message: `${element.fieldName}格式错误`
        })
      }
      if (element.fieldName === "个人邮箱" || element.fieldName === "邮箱") {
        fields[element.fieldCode].decorator.rules.push({
          pattern: "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*",
          message: "邮箱格式错误"
        });
      }

    }
  });

  return fields
}
